how to get data from json array in php

71

$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;
 $data = json_decode($json);
$json = '
{
    "type": "donut",
    "name": "Cake",
    "toppings": [
        { "id": "5002", "type": "Glazed" },
        { "id": "5006", "type": "Chocolate with Sprinkles" },
        { "id": "5004", "type": "Maple" }
    ]
}';

$yummy = json_decode($json, true);

echo $yummy['toppings'][2]['type']; //Maple

Comments

Submit
0 Comments